import ProfileAction from "../../store/actions/profile";
import store from "../../store/store";
import { AxiosError } from "axios";
import { message } from "bigbear-ui";
import { useEffect } from "react";
import { push } from "connected-react-router";

function useAuth(pathName: string) {
	useEffect(() => {
		store.dispatch(ProfileAction.validate()).catch((error: AxiosError) => {
			message.danger(error.message, {});
			if (pathName !== "/profile") {
				setTimeout(() => {
					store.dispatch(push("/profile"));
				}, 3000);
			}
		});
	}, [pathName]);
}
export default useAuth;
